package cn.tedu.signin.management.controller;

import cn.tedu.common.pojo.authentication.CurrentPrincipal;
import cn.tedu.common.web.JsonResult;
import cn.tedu.signin.management.pojo.param.SingInAddNew;
import cn.tedu.signin.management.service.SingInService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 处理评论相关请求的控制器类
 *
 * @author java@傲绝
 * @version 3.0
 */
@Slf4j
@RestController
@RequestMapping("/sign-ins")
@Validated
@Api(tags = "1. 签到管理")
public class SingInController {

   @Autowired
    SingInService singInService;


    @PostMapping("/add-new/{serialNumber}")
    // @PreAuthorize("hasAuthority('/content/article/simple')")
    @ApiOperation("签到管理")
    @ApiOperationSupport(order = 100)
    public JsonResult addNew(@AuthenticationPrincipal @ApiIgnore CurrentPrincipal currentPrincipal,
                             @Valid SingInAddNew singInAddNew,@PathVariable String serialNumber){
        log.debug("开始处理【发布评论】的请求，参数：{}", singInAddNew);

        Long serialNumber1=Long.parseLong(serialNumber);

        singInService.insert(currentPrincipal,singInAddNew,serialNumber1);
        return JsonResult.ok();
    }




    @PostMapping("/")
    // @PreAuthorize("hasAuthority('/content/article/simple')")
    @ApiOperation("签到查询")
    @ApiOperationSupport(order = 101)
    public JsonResult selectList(){



        return JsonResult.ok( singInService.serlectList());
    }

}
